package mytomcat.core;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author swc
 * @version     V1.0
 * @date 2020/4/20 0020 上午 9:53
 */
public class MyRequest {

    private String url;

    private String method;

    //当前端口
    private Integer port;

    public MyRequest(InputStream inputStream,Integer port) throws IOException {
        String httpRequest ="";
        byte[] httpRequestBytes =new byte[1024];
        int length = 0;
        if((length = inputStream.read(httpRequestBytes))>0){
            httpRequest = new String(httpRequestBytes,0,length);
        }

        //非空处理
        if(httpRequest!=null && !"".equalsIgnoreCase(httpRequest.trim())){
            String httpHead = httpRequest.split("\n")[0];
            url = httpHead.split("\\s")[1];
            method = httpHead.split("\\s")[0];
        }

        this.port =port;
    }


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }
}
